import { AfterViewChecked, Component, ElementRef, EventEmitter, Injector, Output, ViewChild } from '@angular/core';
import { AppConsts } from '@shared/AppConsts';
import { AppComponentBase } from '@shared/common/app-component-base';

import { OrganizationUnitDto, ProfileServiceProxy, TaskForModelDto, OutsourcingWorkFlowModel,TaskServiceProxy, OutsourcingWorkFlowServiceProxy, UserServiceProxy, OutsourcingDto, OutsourcingWorkFlowStepUserDto, OutsourcingWorkFlowInputDto, OutsourcingFormInputDto, SupplierServiceProxy, OutsouringServiceProxy } from '@shared/service-proxies/service-proxies';
import { ModalDirective } from 'ngx-bootstrap';
import * as _ from 'lodash';
import { finalize } from 'rxjs/operators';

import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent';
import { Paginator } from 'primeng/components/paginator/paginator';
import { Table } from 'primeng/components/table/table';
import { PrimengTableHelper } from 'shared/helpers/PrimengTableHelper';
import { SelectItem, SelectItemGroup } from 'primeng/api';

@Component({
  selector: 'awaitQuotationForm',
  templateUrl: './AwaitQuotationForm.component.html',
  styleUrls: ['./AwaitQuotationForm.component.css']
})
export class AwaitQuotationFormComponent extends AppComponentBase {
  @ViewChild('createOrEditModal') modal: ModalDirective;

  active = false;
  saving = false;
  tabPanels = [];
  supplierUnits = [];
  SupplierAyy: SelectItem[];
  workflowid: string;
  workflow: OutsourcingWorkFlowModel = new OutsourcingWorkFlowModel();
  constructor(injector: Injector,
    private _supplierService: SupplierServiceProxy,
    private _outSourcingworkflowServiceProxy: OutsourcingWorkFlowServiceProxy
  ) {
    super(injector);

  }
  show(id: string): void {
    this.tabPanels = []; //初始化为空
    this.workflowid = id;
    this.initForm();
    this.active = true;
    this.modal.show();
  }
  close(): void {
    this.active = false;
    this.modal.hide();
  }
  onShown(): void {
    this._supplierService.getAllSupplierItems().subscribe(resultdata => {
      this.SupplierAyy = resultdata;
    });
  }

  save(): void {
    console.log(this.workflow.id);
    this._outSourcingworkflowServiceProxy.outsourcingFlow_QuotationSubmit(this.workflowid).subscribe(result => {

      this.notify.info(this.l('SavedSuccessfully'));
    })


  }

  initForm(): void {
    console.log(this.workflowid);
    this._outSourcingworkflowServiceProxy.getOutsourcingWorkFlow(this.workflowid).subscribe(dto => {
      this.workflow = dto.workFlowDto;
      this.supplierUnits = dto.workFlowDto.supplierUnit.split(',');
      console.log(this.workflow)
      _.forEach(this.supplierUnits, viewItem => {
        let _a = { title: viewItem };
        this.tabPanels.push(_a);
      });
    });
  }
}
